package com.oracle.zebrafreelytraveling.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.facebook.common.references.SharedReference;
import com.oracle.zebrafreelytraveling.App;

/**
 * Shared工具类
 */
public class SharePreUtil {

	private static Context mContext = App.getContextObject();

	/**
	 * @param keyname 存储数据的key
	 * @param value 存储数据的value
	 * @description shared保存int型数据
     */
	public static void SetShareInt(String keyname,int value){
		SharedPreferences sp = PreferenceManager
					.getDefaultSharedPreferences(mContext);
		sp.edit().putInt(keyname, value).apply();
	}

	/**
	 * @param keyname 存储数据的key
	 * @description shared获取int型数据
	 */
	public static int GetShareInt(String keyname){
		SharedPreferences sp = PreferenceManager
					.getDefaultSharedPreferences(mContext);
		return sp.getInt(keyname, -1);
	}

	/**
	 * @param keyname 存储数据的key
	 * @param value 存储数据的value
	 * @description shared保存String类型数据
	 */
	public static void SetShareString(String keyname,String value){
		SharedPreferences sp = PreferenceManager
					.getDefaultSharedPreferences(mContext);
		sp.edit().putString(keyname, value).apply();
	}

	/**
	 * @param keyname 存储数据的key
	 * @description shared获取String类型数据
	 */
	public static String GetShareString(String keyname){
		SharedPreferences sp = PreferenceManager
					.getDefaultSharedPreferences(mContext);
		return sp.getString(keyname, "");
	}

	/**
	 * @param keyname 存储数据的key
	 * @description shared获取boolean类型数据
	 */
	public static boolean GetShareBoolean(String keyname){
		SharedPreferences sp = PreferenceManager
					.getDefaultSharedPreferences(mContext);
		return sp.getBoolean(keyname, false);
	}

	/**
	 * @param keyname 存储数据的key
	 * @param value 存储数据的value
	 * @description shared保存boolean类型数据
	 */
	public static void SetShareBoolean(String keyname,boolean value){
		SharedPreferences sp = PreferenceManager
					.getDefaultSharedPreferences(mContext);
		sp.edit().putBoolean(keyname, value).apply();
	}

}
